<template>
    <div class="container">
        <div class="login-content">
            <a href="#" class="banner-box"></a>
            <div class="login-box">
                <h1>账号登录</h1>
                <input type="text" v-model="loginUser" placeholder="账号" />
                <input type="password" v-model="passWord" placeholder="密码" />
                <button class="login-btn" @click="change">登录</button>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            loginUser: "",
            passWord: "",
        };
    },
    methods: {
        change() {
            if (!this.loginUser || !this.passWord) {
                this.$message({
                    message: "账号或密码为空",
                    type: "warning",
                    duration: 1000,
                });
                return;
            }
            const loginInfo = {
                loginUser: this.loginUser,
                passWord: this.passWord,
            };
            const result = this.$store.dispatch("loginUser/login", loginInfo);
            result.then((data) => {
                if (data == "登录成功") {
                    this.$message({
                        message: data,
                        type: "success",
                        duration: 1000,
                    });
                    this.$router.push("/editBlog");
                } else {
                    this.$message({
                        message: data,
                        type: "error",
                        duration: 1000,
                    });
                }
            });
        },
    },
    mounted() {
        this.$store.commit("siteInfo/modifyTitle", {
            title: "Login",
            note: "Study hard and you will reap the rewards",
        });

        document.onkeydown = (key) => {
            if (key.keyCode === 13) {
                this.change();
            }
        };
    },
};
</script>

<style scoped>
* {
    margin: 0;
    padding: 0;
}

.container {
    width: 100vw;
    height: 100vh;
    background: url(../../public/bg.jpg) no-repeat;
    background-size: cover;
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-content {
    position: relative;
    width: 800px;
    height: 360px;
    background-color: rgb(52, 0, 73);
    border-radius: 30px;
    padding: 30px;
}

.banner-box {
    display: inline-block;
    width: 500px;
    height: 100%;
    /* background-color: rgb(0, 92, 92); */
    background: url(../../public/bg.jpg) no-repeat;
    background-size: cover;
    border-radius: 20px 0 0 20px;
}

.login-box {
    width: 330px;
    height: 100%;
    /* background-color: rgb(172, 106, 26); */
    position: absolute;
    top: 0;
    right: 0;
    border-radius: 0 30px 30px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.login-box > h1 {
    font-size: 36px;
    margin: 60px 0;
    color: #fff;
}

.login-box > input {
    margin-bottom: 20px;
    width: 200px;
    height: 36px;
    padding: 0 20px;
    border-radius: 36px;
    border: none;
    outline: none;
    font-size: 18px;
}

.login-btn {
    margin-top: 20px;
    width: 240px;
    height: 40px;
    background-color: rgb(122, 0, 223);
    border: none;
    border-radius: 40px;
    color: #fff;
    font-size: 18px;
}

@media screen and (max-width: 900px) {
    .login-content {
        margin: 0 30px;
    }

    .banner-box {
        border-radius: 20px;
    }

    .login-box {
        background-color: rgba(52, 0, 73, 0.5);
    }
}

@media screen and (max-width: 600px) {
    .container {
        background: url(../../public/bg.jpg) no-repeat center;
    }

    .login-content {
        background-color: rgba(52, 0, 73, 0);
    }

    .banner-box {
        display: none;
    }

    .login-box {
        position: initial;
        margin: -40px auto;
        background-color: rgba(52, 0, 73, 0);
    }
}
</style>
